<template>
  <div class="page-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>商品管理</span>
          <el-button type="primary" @click="handleAdd">新增商品</el-button>
        </div>
      </template>

      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="name" label="商品名称" />
        <el-table-column prop="category" label="分类" />
        <el-table-column prop="price" label="价格">
          <template #default="{ row }">
            ¥{{ row.price }}
          </template>
        </el-table-column>
        <el-table-column prop="stock" label="库存" />
        <el-table-column prop="status" label="状态">
          <template #default="{ row }">
            <el-tag :type="row.status === '上架' ? 'success' : 'info'">
              {{ row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button size="small" @click="handleEdit(row)">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        v-model:current-page="currentPage"
        :page-size="10"
        :total="50"
        layout="total, prev, pager, next"
        style="margin-top: 20px; justify-content: flex-end;"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const currentPage = ref(1)

const tableData = ref([
  { id: 1, name: 'iPhone 15 Pro', category: '手机', price: 7999, stock: 100, status: '上架' },
  { id: 2, name: 'MacBook Pro', category: '电脑', price: 12999, stock: 50, status: '上架' },
  { id: 3, name: 'AirPods Pro', category: '耳机', price: 1999, stock: 200, status: '上架' },
  { id: 4, name: 'iPad Air', category: '平板', price: 4799, stock: 80, status: '下架' },
  { id: 5, name: 'Apple Watch', category: '手表', price: 2999, stock: 150, status: '上架' }
])

const handleAdd = () => {
  ElMessage.info('新增商品功能')
}

const handleEdit = (row) => {
  ElMessage.info(`编辑商品：${row.name}`)
}

const handleDelete = (row) => {
  ElMessage.warning(`删除商品：${row.name}`)
}
</script>

<style scoped>
.page-container {
  width: 100%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
